"use strict";
var mongoose_1 = require('mongoose');
var DBManager = (function () {
    function DBManager() {
        this.modleMap = {};
        this.db = new mongoose_1.Mongoose();
        this.db.connect("mongodb://kinglo:isgeek317@chuxin.fm:27017/kapi");
        this.initMUser();
        this.initMToken();
        this.initMProject();
        this.initMGroup();
        this.initMDoc();
    }
    DBManager.getInstance = function () {
        if (!this.instance) {
            return new DBManager();
        }
        return this.instance;
    };
    DBManager.prototype.getModel = function (modelName) {
        return this.modleMap[modelName];
    };
    DBManager.prototype.initMToken = function () {
        var schema = new mongoose_1.Schema({
            token: String,
            user: { type: mongoose_1.Schema.Types.ObjectId, ref: 'user' },
            createdAt: { type: Date, default: Date.now }
        });
        var mToken = this.db.model("token", schema);
        this.modleMap["mToken"] = mToken;
    };
    DBManager.prototype.initMUser = function () {
        var schema = new mongoose_1.Schema({
            username: String,
            password: String,
            nickname: String,
            avatar: String,
            createdAt: { type: Date, default: Date.now }
        });
        var mUser = this.db.model("user", schema);
        this.modleMap["mUser"] = mUser;
    };
    DBManager.prototype.initMProject = function () {
        var schema = new mongoose_1.Schema({
            title: String,
            description: String,
            open: Boolean,
            user: { type: mongoose_1.Schema.Types.ObjectId, ref: 'user' },
            createdAt: { type: Date, default: Date.now }
        });
        var mProject = this.db.model("project", schema);
        this.modleMap["mProject"] = mProject;
    };
    DBManager.prototype.initMGroup = function () {
        var schema = new mongoose_1.Schema({
            name: String,
            description: String,
            project: { type: mongoose_1.Schema.Types.ObjectId, ref: 'project' },
            createdAt: { type: Date, default: Date.now }
        });
        var mGroup = this.db.model("group", schema);
        this.modleMap["mGroup"] = mGroup;
    };
    DBManager.prototype.initMDoc = function () {
        var schema = new mongoose_1.Schema({
            name: String,
            action: String,
            description: String,
            httpMethod: String,
            url: String,
            params: [{
                    name: String,
                    description: String,
                    paramType: String,
                    paramStyle: String,
                    optional: Boolean
                }],
            resps: [{
                    respCode: String,
                    description: String,
                    respType: String,
                    content: String
                }],
            group: { type: mongoose_1.Schema.Types.ObjectId, ref: 'group' },
            project: { type: mongoose_1.Schema.Types.ObjectId, ref: 'project' },
            createdAt: { type: Date, default: Date.now }
        });
        var mDoc = this.db.model("doc", schema);
        this.modleMap["mDoc"] = mDoc;
    };
    return DBManager;
}());
exports.DBManager = DBManager;
